﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for VentaBLL
/// </summary>
public class VentaBLL
{
    public static List<Venta> GetVentas()
    {
        DSVentaTableAdapters.VentasDSTableAdapter tableadapter = new DSVentaTableAdapters.VentasDSTableAdapter();
        DSVenta.VentasDSDataTable datatable = tableadapter.GetVentas();
        List<Venta> listaVentas = new List<Venta>();
        if (datatable != null)
        {
            foreach (DSVenta.VentasDSRow row in datatable)
            {
                Venta venta = RowToDTO(row);
                listaVentas.Add(venta);
            }
        }
        return listaVentas;
    }

    public static void InsertVenta(Venta v)
    {
        DSVentaTableAdapters.VentasDSTableAdapter tableadapter = new DSVentaTableAdapters.VentasDSTableAdapter();
        if (v != null)
        {
            tableadapter.InsertVenta(v.dtVenta_fecha, v.iCliente_id, v.dVenta_monto, v.iProducto_id);
        }
    }

    public static Venta RowToDTO(DSVenta.VentasDSRow row)
    {
        return (row != null) ? new Venta(row.iVenta_id, row.sFecha_dt, row.iCliente_id, row.dMonto_total, row.iProducto_id) : null;
    }
}